
local mt = ac.skill['秘法天球']

function mt:dmg_tip()
    local hero = self.owner
    if hero then
        if japi.GetKeyState(KEY.ALT) then
            return ('|cffffcc99%0.f%%智力|r'):format(self.data1)
        else
            return ('|cffffcc99%s|r(|cff00ff00按alt查看公式|r)'):format(format_number1(hero:get('智力') * self.data1/100))
        end
    end
end

function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(200,function()
        if hero:get('魔法')>50 then
            if self.buff==nil then
                self.buff = hero:add_buff '秘法天球'{skill = self}
            end
        else
            if self.buff then
                self.buff:remove()
                self.buff = nil
            end
        end
    end))
    self:gc(function()
        if self.buff then
            self.buff:remove()
            self.buff = nil
        end
    end)
end

local buff = ac.buff['秘法天球']
buff.keep = true
buff.model = [[Abilities\Spells\Undead\OrbOfDeath\AnnihilationMissile.mdl]]
function buff:on_add()
    local hero = self.owner
    local skill = self.skill
    self:gc(hero:add_buff '弹道'{
        arc = 0,
        speed = 1500,
        model = self.model,
    })
    self:gc(hero:event '单位-攻击命中'(function(_,_,target,data)
        local damage = hero:get('智力') * skill.data1/100
        hero:add('魔法',-skill.cost)
        target:damage{
            source = hero,
            damage = damage,
            skill = skill,
        }
    end))
end


